home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindspring.com!usenet
- From: rudd@mindspring.com (Justin Rudd)
- Newsgroups: comp.lang.c++
- Subject: Re: Need help!
- Date: Thu, 14 Mar 1996 04:55:40 GMT
- Organization: MindSpring Enterprises
- Message-ID: <4i8922$4pi@firebrick.mindspring.com>
- References: <Do858A.Btr@iquest.net>
- Reply-To: rudd@mindspring.com
- NNTP-Posting-Host: rudd.mindspring.com
- X-Newsreader: Forte Free Agent v0.55
-
- OK...sorry there are no > in front of what you originally posted
- because I played with the code a bit and reformatted to a form I could
- easily read :-)
-
- Well anyway...I'll just inject my comments in the code below...
-
- #include <dos.h>
- #include <stdlib.h>
- #include <math.h>
- #include <dir.h>
- #include <stdio.h>
- #include <string.h>
- #include <conio.h>
-
- struct data
- {
- char name[50];
- };
-
- class reg
- {
- public:
- void init(void);
- void desc(struct data *dptr);
- };
-
- void reg::init(void)
- {
- }
-
- void reg::desc(struct data *dptr)
- {
- //First off you were using the pointer directly...
- //I make it a practice to never do that...I always make a temp
- //pointer.
- data* temp = NULL;
-
- temp = dptr;
-
- int y=0,x=0;
-
- for(y=0;y<25;y++)
- {
- for(x=0;x<=y;x++)
- {
- strcat(temp->name,"A");
- }
-
- printf("%s\n", temp->name );
- temp++;
- getch();
- }
-
- /* Here is the problem area*/
-
- //With a temp pointer you don't even have to worry about going
- //backwards you can just start you second loop with your parameter
- //pointer dptr.
- //for(y=0;y<25;y++) dptr--;
-
- for(y=0;y<25;y++)
- {
- printf("\n%4d %s",y,dptr->name);
- // also in you original code...you never incremented dptr :-)
- dptr++;
- getch();
- }
- }
-
- int main(void)
- {
- reg reg1;
-
- data rrdata[25];
- data *rptr;
-
- memset(rrdata,0,sizeof(data)*25);
-
- reg1.init();
-
- rptr = rrdata;
-
- reg1.desc(rptr);
-
- for(int x=0;x<25;x++)
- {
- printf("\n%4d %s",x,rrdata[x].name);
- }
-
- return 0;
- }
-
- Hope this helps...
-
- Justin
-
-